package com.deram.ctin.dependencies.rest.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                    .apis(RequestHandlerSelectors.basePackage("com.deram.ctin.rest"))
                    .build()
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(false);
    }

    private ApiInfo apiInfo() {
        StringBuilder desc = new StringBuilder();
        desc.append("1.请求路径，必须加上rest-*<br/>");
        desc.append("2.状态码<br/>");
        desc.append("&nbsp;&nbsp;200：成功<br/>");
        desc.append("&nbsp;&nbsp;400：失败，返回code和message，code为业务错误码，message为错误信息<br/>");
        desc.append("&nbsp;&nbsp;500：服务器异常，直接提示“服务异常，请稍后重试”<br/>");
        ApiInfo apiInfo = new ApiInfo(
                "中国征信项目接口文档",
                desc.toString(),
                "1.0",
                "urn:tos",
                new Contact("", "", ""),
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<VendorExtension>()
        );
        return apiInfo;
    }
}
